<?php

include_once 'excel_reader2.php';

class Cities_SpreadSheet_Reader {

    public $spreadsheet_file_path;
    public $spreadsheet = NULL;
    
    const START_ROW = '5';
    const STATE_ACRONYM_COLUMN = 'A';
    const CITY_NAME_COLUMN = 'D';
    
    //$states_names = array('AC' => 'Acre', 'AL' => 'Alagoas', 'AM' => 'Amazonas',
    //    'AP' => 'Amapá', 'BA' => 'Bahia', 'CE' => 'Ceará', 'DF' => 'Distrito Federal',
    //    'ES' => 'Espírito Santo', 'GO' => 'Goiás', 'MA' => 'Maranhão', 'MG' => 'Minas Gerais',
    //   'MS' => 'Mato Grosso do Sul', 'MT' => 'Mato Grosso', 'PA' => 'Pará', 'PB' => 'Paraíba',
    //    'PE' => 'Pernambuco', 'PI' => 'Piauí', 'PR' => 'Paraná', 'RJ' => 'Rio de Janeiro',
    //    'RN' => 'Rio Grande do Norte', 'RO' => 'Rondônia', 'RR' => 'Roraima', 'RS' => 'Rio Grande do Sul',
    //    'SC' => 'Santa Catarina', 'SE' => 'Sergipe', 'SP' => 'São Paulo', 'TO' => 'Tocantins');
    
    public function __construct($spreadsheet_file_path = '') {
        $this->spreadsheet_file_path = $spreadsheet_file_path;
    }
    
    public function load_spreadsheet() {
        $this->spreadsheet = new Spreadsheet_Excel_Reader($this->spreadsheet_file_path);
    }
    
    private function is_spreadsheet_loaded() {
        if (is_null($this->spreadsheet)) {
            throw new Exception('O método load_spreadsheet deve ser chamado primeiro.');
        }
    }
    
    public function get_state_acronym() {
        $this->is_spreadsheet_loaded();
        
        return $this->spreadsheet->val(self::START_ROW, self::STATE_ACRONYM_COLUMN);
    }
    
    public function get_cities_names() {
        $this->is_spreadsheet_loaded();
        
        $cities_names = array();
        $current_row = self::START_ROW;
        while($this->spreadsheet->val($current_row, self::CITY_NAME_COLUMN) != '') {
            $cities_names[] = $this->spreadsheet->val($current_row, self::CITY_NAME_COLUMN);
            $current_row++;
        }
        return $cities_names;
    }
    

    
    
    
    
}

?>
